
/*
 * Desenvolvimento para WEB
 * 
 * NOME: Vitor Augusto Graciani           RA: 345270
 * NOME: Felipe Petruz Brina              RA: 345083
 * NOME: Diego Zamboni Latance            RA: 344990
 * NOME: Rafael Claudio Domene            RA: 345040
 * NOME: Vinicius Rodrigues de Campos     RA: 345350
 * 
 */
package model;

import auxiliar.ConnectionFactory;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ConsultaLateralDAO {

    private Connection conn;

    public ConsultaLateralDAO() throws DAOException {
        try {
            this.conn = ConnectionFactory.getConnection();

        } catch (Exception e) {
            throw new DAOException("Erro: " + ":\n" + e.getMessage());
        }
    }

    public ArrayList<ConsultaLateralBEAN> ConsultaLateral(String categoria) throws DAOException {
        PreparedStatement ps = null;
        Connection conn = null;
        ResultSet rs = null;
        try {
            String SQL = "EXECUTE consultaCategoriasTipos '"+categoria+"'";
            conn = this.conn;
            ps = conn.prepareStatement(SQL);
            rs = ps.executeQuery();
            ArrayList<ConsultaLateralBEAN> list = new ArrayList<ConsultaLateralBEAN>();
            while (rs.next()) {
                
                String categoria2 = rs.getObject("categorie").toString();
                String tipo = rs.getObject("type").toString();
                
                ConsultaLateralBEAN tipo1 = new ConsultaLateralBEAN(tipo);
                
                list.add(tipo1);
            }
            return list;
        } catch (SQLException sqle) {
            throw new DAOException(sqle);
        } finally {
            ConnectionFactory.closeConnection(conn, ps, rs);
        }

    }
}
